﻿namespace BM.Tools.WebControls.MForm.Navigation
{
    using System.Collections.Generic;

    /// <summary>
    /// A query class for searching parents and children in a node tree.    
    /// </summary>
    /// <typeparam name="T">
    /// the type on which the query will be made
    /// </typeparam>
    public abstract class NavigatorQuery<T>
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="NavigatorQuery{T}"/> class.
        /// </summary>
        /// <param name="item">
        /// The item on which the query is made.
        /// </param>
        protected NavigatorQuery(T item)
        {
            Item = item;
        }

        /// <summary>
        /// Gets DescendantsAndSelf.
        /// </summary>
        /// <value>
        /// The descendants and self.
        /// </value>
        public abstract IEnumerable<T> DescendantsAndSelf
        {
            get;
        }

        /// <summary>
        /// Gets the Item.
        /// </summary>
        /// <value>
        /// The item on which the query is made.
        /// </value>
        protected T Item
        {
            get;
            private set;
        }

        /// <summary>
        /// Returns items' children.
        /// </summary>
        /// <returns>
        /// Items' children.
        /// </returns>
        public abstract IEnumerable<T> FindChildren();

        /// <summary>
        /// finds all the children with a local name 
        /// </summary>
        /// <param name="localName">
        /// The local name.
        /// </param>
        /// <returns>
        /// the enumeration of children with a local name
        /// </returns>
        public abstract IEnumerable<T> FindChildrenByLocalName(string localName);

        /// <summary>
        /// finds all the children with a name 
        /// </summary>
        /// <param name="name">
        /// The name to be checked.
        /// </param>
        /// <returns>
        /// the enumeration of children with a name
        /// </returns>
        public abstract IEnumerable<T> FindChildrenByName(string name);

        /// <summary>
        /// finds all the children with a prefix
        /// </summary>
        /// <param name="prefix">
        /// The prefix.
        /// </param>
        /// <returns>
        /// the enumeration of children with a prefix
        /// </returns>
        public abstract IEnumerable<T> FindChildrenByPrefix(string prefix);

        /// <summary>
        /// Returns items' parent.
        /// </summary>
        /// <returns>
        /// Items' parent.
        /// </returns>
        public abstract T FindParent();

        /// <summary>
        /// checks if item position equals the specified value
        /// </summary>
        /// <param name="position">
        /// The position to be compared to.
        /// </param>
        /// <returns>
        /// does the position equal the specified value
        /// </returns>
        public abstract bool IndexEquals(int position);

        /// <summary>
        /// returns information if the item is attribute
        /// </summary>        
        /// <returns>
        /// is item attribute
        /// </returns>
        public abstract bool IsAttribute();

        /// <summary>
        /// returns information if the item is element
        /// </summary>        
        /// <returns>
        /// is item element
        /// </returns>
        public abstract bool IsElement();

        /// <summary>
        /// checks if item name equals the specified value
        /// </summary>
        /// <param name="name">
        /// The name to be compared to.
        /// </param>
        /// <returns>
        /// does the name equal the specified value
        /// </returns>
        public abstract bool NameEquals(string name);
    }
}